//
//  HPFuDaoView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/4.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "HPFuDaoView.h"
#import "HPHeaderView.h"
@implementation HPFuDaoView

/* 
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self initOption];
        [self layout];
    }
    return self;
}
- (UIView *)top_view{
    if (!_top_view) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        _top_view = view;
    }
    return _top_view;
}
- (UIImageView *)leftImageView{
    if (!_leftImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"home_fudao"];
        _leftImageView = imageView;
    }
    return _leftImageView;
}
- (UILabel *)work_label{
    if (!_work_label) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"辅导";
        _work_label = label;
    }
    return _work_label;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(705.5,493.5,289,11.5);
        label.numberOfLines = 0;
        label.textAlignment = 2;
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"回答问题：3月20 14:00 周五    共计：18人 20个问题" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];
        label.attributedText = string;
        _timeLabel = label;
    }
    return _timeLabel;
}
- (UILabel *)noDataLabel{
    if (!_noDataLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"当前数据为空";
        label.textAlignment = 1;
        _noDataLabel = label;
    }
    return _noDataLabel;
}
- (void)initSubView{
    [self addSubview:self.top_view];
    [_top_view addSubview:self.leftImageView];
    [_top_view addSubview:self.work_label];
    [_top_view addSubview:self.timeLabel];
    [self addLittleSubView];
//    [self addSubview:self.noDataLabel];
}
- (void)initOption{
    self.backgroundColor = [UIColor whiteColor];
}
- (void)layout{
    [_top_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.height.equalTo(@38);
    }];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@17);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.width.equalTo(@22);
        make.height.equalTo(@19);
    }];
    [_work_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftImageView.mas_right).offset(13);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.width.equalTo(@60.5);
        make.height.equalTo(@15.0);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.top_view.mas_right).offset(-15);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.left.equalTo(self.work_label.mas_right);
        make.height.equalTo(@20);
    }];
    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
}
#pragma mark - 点击箭头的方法
- (void)arrow_click{
    
}
#pragma mark - 添加子视图
- (void)addLittleSubView{
    for (int i = 0; i<18; i++) {
        CGFloat W = 46*fw;
        CGFloat H = 46*fh;
        CGFloat X = 17*(i%7+1)+W*(i%7);
        CGFloat Y = 15*(i/7)+i/7*H+56*fh;
        HPHeaderView *view = [[HPHeaderView alloc]initWithFrame:CGRectMake(X, Y, W, H)];
        view.tag = 20+i;
        view.hidden = YES;
        [self addSubview:view];
    }
}
- (void)updateView{
    for (int i = 0; i<_dataArray.count; i++) {
        _noDataLabel.hidden = NO;
        if (i > 18) {
            return;
        }
        HPHeaderView *view = (HPHeaderView *)[self viewWithTag:20+i];
        NSDictionary *dict = _dataArray[i];
        view.nameLabel.text = [dict nilObjectForKey:@"name"];
        view.hidden = NO;
    }
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0, 39)];
    [path addLineToPoint:CGPointMake(fw*452, 39)];
    [path setLineWidth:1];
    [LINCOLOR setStroke];
    [path stroke];
}
@end
